from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.

class User(AbstractUser):
    username = models.CharField(max_length=255, unique=True, verbose_name="用户名")
    nickname = models.CharField(default="", max_length=255, verbose_name="昵称", null=True, blank=True)
    password = models.CharField(max_length=255, verbose_name="密码")
    email = models.EmailField(unique=True)

    class Meta:
        db_table = "user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name


class Roles(models.Model):
    name = models.CharField(max_length=255, unique=True, null=True)


class UrlAddress(models.Model):
    url_address = models.CharField(max_length=255)


class UserRoles(models.Model):
    user = models.ForeignKey(to=User, on_delete=models.CASCADE)
    role = models.ForeignKey(to=Roles, on_delete=models.CASCADE)

    class Meta:
        db_table = "user_roles"


class RoleUrlAddress(models.Model):
    role = models.ForeignKey(to=Roles, on_delete=models.CASCADE)
    url_address = models.ForeignKey(to=UrlAddress, on_delete=models.CASCADE)

    class Meta:
        db_table = "role_urladdress"
